package io.easyspring.common.generator.config;

import io.easyspring.common.generator.convertor.ModelNameConvertor;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 生成器输出路径的配置类
 *
 * @author summer
 * @version V1.0.0-RELEASE
 * DateTime 2019-05-11 18:56
 */
@AllArgsConstructor
@Data
public class GeneratorOutputDirConfig {

    /**
     * 项目的根路径
     */
    private String sourceCodeRootDir;
    /**
     * 测试代码的根路径
     */
    private String testCodeRootDir;
    /**
     * 服务的路径
     */
    private String serverPath;
    /**
     * 模块名称
     */
    private String modelName;
    /**
     * 包的根路径
     */
    private String basePackagePath;

    /**
     * 代码的相对路径
     */
    private static String SOURCE_CODE_PATH = "/src/main/java";
    private static String TEST_CODE_PATH = "/src/test/java";
    private static String MAPPER_CODE_PATH = "/src/main/resources/mapper";

    /**
     * 项目名称的后缀
     */
    private static String MODEL_PROJECT_SUFFIX = "-core";
    private static String SERVICE_PROJECT_SUFFIX = "-service";
    public static String API_PROJECT_SUFFIX = "-api";
    private static String CLIENT_PROJECT_SUFFIX = "-client";
    private static String TEST_PROJECT_SUFFIX = "-test";

    private static String MODEL_PACKAGE_PATH_SUFFIX = "/model";
    private static String MAPPER_PACKAGE_PATH_SUFFIX = "/mapper";
    private static String SERVICE_PACKAGE_PATH_SUFFIX = "/service";
    private static String SERVICE_IMPL_PACKAGE_PATH_SUFFIX = "/service/impl";
    private static String API_PACKAGE_PATH_SUFFIX = "/controller";
    private static String CLIENT_PACKAGE_PATH_SUFFIX = "/client";
    private static String CLIENT_FALLBACK_PACKAGE_PATH_SUFFIX = "/client/fallback";
    //private static String SERVER_API_SUFFIX = "-server-api";


    /**
     * model
     */
    public String getModelDir(){
        // 拼接到父级项目
        return this.sourceCodeRootDir + serverPath +
                // 拼接到具体的项目
                serverPath + MODEL_PROJECT_SUFFIX +
                // 拼接到代码输出的路径
                SOURCE_CODE_PATH +
                // 拼接包路径和模块路径
                basePackagePath + ModelNameConvertor.convert2ModelPath(modelName) + MODEL_PACKAGE_PATH_SUFFIX;
    }

    /**
     * service
     */
    public String getMapperDir(){
        // 拼接到父级项目
        return this.sourceCodeRootDir + serverPath +
                // 拼接到具体的项目
                serverPath + SERVICE_PROJECT_SUFFIX +
                // 拼接到代码输出的路径
                SOURCE_CODE_PATH +
                // 拼接包路径和模块路径
                basePackagePath + ModelNameConvertor.convert2ModelPath(modelName) + MAPPER_PACKAGE_PATH_SUFFIX;
    }
    public String getMapperXmlDir(){
        // 拼接到父级项目
        return this.sourceCodeRootDir + serverPath +
                // 拼接到具体的项目
                serverPath + SERVICE_PROJECT_SUFFIX +
                // 拼接到代码输出的路径
                MAPPER_CODE_PATH +
                // 拼接包路径和模块路径
                ModelNameConvertor.convert2ModelPath(modelName);
    }
    public String getServiceDir(){
        // 拼接到父级项目
        return this.sourceCodeRootDir + serverPath +
                // 拼接到具体的项目
                serverPath + SERVICE_PROJECT_SUFFIX +
                // 拼接到代码输出的路径
                SOURCE_CODE_PATH +
                // 拼接包路径和模块路径
                basePackagePath + ModelNameConvertor.convert2ModelPath(modelName) + SERVICE_PACKAGE_PATH_SUFFIX;
    }
    public String getServiceImplDir(){
        // 拼接到父级项目
        return this.sourceCodeRootDir + serverPath +
                // 拼接到具体的项目
                serverPath + SERVICE_PROJECT_SUFFIX +
                // 拼接到代码输出的路径
                SOURCE_CODE_PATH +
                // 拼接包路径和模块路径
                basePackagePath + ModelNameConvertor.convert2ModelPath(modelName) + SERVICE_IMPL_PACKAGE_PATH_SUFFIX;
    }

    /**
     * api
     */
    public String getControllerDir(){
        // 拼接到父级项目
        return this.sourceCodeRootDir + serverPath +
                // 拼接到具体的项目
                serverPath + API_PROJECT_SUFFIX +
                // 拼接到代码输出的路径
                SOURCE_CODE_PATH +
                // 拼接包路径和模块路径
                basePackagePath + ModelNameConvertor.convert2ModelPath(modelName) + API_PACKAGE_PATH_SUFFIX;
    }

    /**
     * client
     */
    public String getClientDir(){
        // 拼接到父级项目
        return this.sourceCodeRootDir + serverPath +
                // 拼接到具体的项目
                serverPath + CLIENT_PROJECT_SUFFIX +
                // 拼接到代码输出的路径
                SOURCE_CODE_PATH +
                // 拼接包路径和模块路径
                basePackagePath + ModelNameConvertor.convert2ModelPath(modelName) + CLIENT_PACKAGE_PATH_SUFFIX;
    }
    public String getClientFallbackDir(){
        // 拼接到父级项目
        return this.sourceCodeRootDir + serverPath +
                // 拼接到具体的项目
                serverPath + CLIENT_PROJECT_SUFFIX +
                // 拼接到代码输出的路径
                SOURCE_CODE_PATH +
                // 拼接包路径和模块路径
                basePackagePath + ModelNameConvertor.convert2ModelPath(modelName) + CLIENT_FALLBACK_PACKAGE_PATH_SUFFIX;
    }

    /**
     * test
     */
    public String getServiceTestDir(){
        // 拼接到父级项目
        return this.testCodeRootDir +
                // 拼接到具体的项目
                serverPath + TEST_PROJECT_SUFFIX +
                // 拼接到代码输出的路径
                TEST_CODE_PATH +
                // 拼接包路径和模块路径
                basePackagePath + ModelNameConvertor.convert2ModelPath(modelName) + SERVICE_IMPL_PACKAGE_PATH_SUFFIX;
    }
    public String getControllerTestDir(){
        // 拼接到父级项目
        return this.testCodeRootDir +
                // 拼接到具体的项目
                serverPath + TEST_PROJECT_SUFFIX +
                // 拼接到代码输出的路径
                TEST_CODE_PATH +
                // 拼接包路径和模块路径
                basePackagePath + ModelNameConvertor.convert2ModelPath(modelName) + API_PACKAGE_PATH_SUFFIX;
    }


}
